package principal;

import interfac.Window;

import java.util.ArrayList;
import java.util.List;

import modelo.Aluno;
import modelo.Link;


import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import function.Carregar;


public class Main {
	
	
	public static void main(String[] args){
				
		Window w = new Window( init());
		System.out.println(w);
	}
	

	public static Graph<Aluno, Link> init(){
		
		Graph<Aluno, Link> g = new SparseMultigraph<Aluno, Link>();
		
		String[][] rms = Carregar.lerTxts();
		
		List<Aluno> list = new ArrayList<Aluno>();
		for (int i = 0; i < rms.length; i++)
			list.add(new Aluno(rms[i][0]));
			
		for (int i = 0; i < rms.length; i++) {
			g.addVertex(list.get(i));
			for (int j = 1; j < rms[i].length; j++) {
				try{
					Aluno s = find(list, new Aluno(rms[i][j]));
					
					g.addEdge(new Link(i+":"+j), list.get(i), s);
					
				}catch(Exception e){
					System.out.println(e.getMessage());
				}
			}		
		}
		return g;
	}

	public static Aluno find(List<Aluno> l, Aluno s){
		for (int i = 0; i < l.size(); i++) {
			if(l.get(i).equals(s))
				return l.get(i);
		}
		throw new RuntimeException(s + " ok");
	}
}
